﻿using Mario.DataFiles;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mario.UI
{
    public partial class LostAndWinForm : Form
    {
        private bool win = false;
        private int score = 0;

        /// <summary>
        /// Inialize variables
        /// </summary>
        /// <param name="win">true if player won</param>
        /// <param name="score">score after game</param>
        public LostAndWinForm(bool win,int score)
        {
            InitializeComponent();
            this.win = win;
            this.score = score;
            saveScore.Hide();
        }

        /// <summary>
        /// On load method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LostAndWinForm_Load(object sender, EventArgs e)
        {
            if (win)
            {
                textLabel.Text = "Congratulation, You Won The Game!!!";
            } 
            else
            {
                textLabel.Text = "Sorry, You Lost The Game!!!";
            }
            scoreLabel.Text = "Your score is : " + score;
        }

        /// <summary>
        /// Ok button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okButton_Click(object sender, EventArgs e)
        {
            textPanel.Hide();
            saveScore.Show();
        }

        /// <summary>
        /// On form close
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LostAndWinForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form is MainWindow1)
                {
                    form.Show();
                    break;
                }
            }
        }

        /// <summary>
        /// Dont save score button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Save score button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            XMLAccess saveScore = new XMLAccess();
            saveScore.SaveToXML(nameTextBox.Text, score);
            MessageBox.Show("Score saved");
            this.Close();
        }

    }
}
